package cn.jtfadmin.activiti.controller.model;


import java.io.InputStream;
import java.util.Locale;

import cn.jtfadmin.base.lang.common.utils.RequestUtils;
import org.activiti.engine.ActivitiException;
import org.apache.commons.io.IOUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 工作流-在线设计器访问stencilset
 */
@RestController
public class StencilsetRestResource {


    /**
     * 工作流-在线设计器访问stencilset
     * @return
     */
    @RequestMapping(value = {"/editor/stencilset"}, method = {RequestMethod.GET}, produces = {"application/json;charset=utf-8"})
    @ResponseBody
    public String getStencilset() {
        Locale requestLocale = RequestUtils.getRequestLocale();
        InputStream stencilsetStream;
        if("CN".equals(requestLocale.getCountry())){
            stencilsetStream= this.getClass().getClassLoader().getResourceAsStream("stencilset-zh-CN.json");
        }
        else {
            stencilsetStream= this.getClass().getClassLoader().getResourceAsStream("stencilset.json");
        }

        try (InputStream is = stencilsetStream){
            return IOUtils.toString(is, "utf-8");
        } catch (Exception var3) {
            throw new ActivitiException("Error while loading stencil set", var3);
        }
    }
}

